/*
 * ListItemDestination.java
 *
 * Created on June 6, 2007, 2:29 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.db;

import org.infoset.xml.Document;
import org.infoset.xml.Item;
import org.infoset.xml.ItemDestination;
import org.infoset.xml.XMLException;
import org.infoset.xml.util.DocumentDestination;

/**
 *
 * @author alex
 */
public class ListItemDestination implements ItemDestination
{
   
   int level = -1;
   DocumentDestination dest = null;
   
   /** Creates a new instance of ListItemDestination */
   public ListItemDestination()
   {
   }
   
   public void onItem(Document doc)
   {
      
   }

   public void send(Item item)
      throws XMLException
   {
      if (item.getType()==Item.ItemType.ElementItem) {
         level++;
         if (level==1) {
            dest = new DocumentDestination();
         }
      }
      if (dest!=null) {
         dest.send(item);
      }
      if (item.getType()==Item.ItemType.ElementEndItem) {
         level--;
         if (level<1 && dest!=null) {
            onItem(dest.getDocument());
            dest = null;
         }
      }
   }
   
}
